# 在文件夹子文件加前缀
import os

def add_prefix_to_files(directory, prefix):
    # 使用os.walk()递归遍历目录
    for root, dirs, files in os.walk(directory):
        for file_name in files:
            # 创建新的文件名
            new_file_name = prefix + file_name
            # 重命名文件
            old_path = os.path.join(root, file_name)
            new_path = os.path.join(root, new_file_name)
            os.rename(old_path, new_path)
            print(f"Renamed {old_path} to {new_path}")

# 使用
directory = r"F:\desk\yolov5\data\dataset/newlabels"  # 替换为你的文件夹路径
prefix = "c"  # 替换为你想要的前缀
add_prefix_to_files(directory, prefix)
